/**
 * Created by AllanXu on 01/03/2016.
 */
define(function (require) {
	var Vue = require('vue'),
		Config = require('config'),
		_ = require('ajax'),
		utilities = require('utilities');

	var app = new Vue({
		el: '#uc_index',
		data: {
			renderObj: {},
			picServer: Config.picServer,
			member: {}
		},
		methods: {
			init: function () {
				utilities.refreshUserInfo(function (data) {
					app.renderObj = data;
					app.member = JSON.parse(decodeURIComponent(atob(sessionStorage.userInfo))).member;
				});
			},
			go: function (url) {
				location.href = url;
			},
			uptz:function(){
                _(Config.SERVICE.USERCENTER.MEMBER_UPTZ, {
                    id: sessionStorage.id
                }, function (data) {
                    if(data.type === 'SUCCESS'){
                    	if(app.member.sfgb==0)
                        	alert('恭喜您脱单成功！');
						else
                        	alert('我们将继续为您服务！');
                        utilities.refreshUserInfo(function (data) {
                            location.reload();
                        });
                    }
                });
			},
			upgrade: function () {
                _(Config.SERVICE.MATES.VERIFY+'?id=' + sessionStorage.id, {}, function(data) {
                    console.log(data);
                    if(data.errmsg.indexOf("择偶") > 0 ){
                        // 择偶条件没有完善跳转到择偶条件
                        if(confirm("为更好地为您提供服务，请在“个人编辑”中完善择偶条件。")){
                            location.href = 'uc_mate_condition.html';
                        }
                    }else if(data.errmsg.indexOf("基本信息") > 0){
                        if(confirm("为更好地为您提供服务，请在“个人编辑”中完善个人资料。")){
                            location.href = 'uc_profile.html';
                        }
                    }else if(data.errmsg.indexOf("形象照") > 0){
                        if(confirm("为更好地为您提供服务，请在“个人编辑”中上传形象照。")){
                            location.href = 'uc_basicInfo.html';
                        }
                    }else{
                        _(Config.SERVICE.USERCENTER.MEMBER_UPGRADE, {
                            id: sessionStorage.id
                        }, function (data) {
                            if(data.type === 'SUCCESS'){
                                alert('您的升级申请已提交，请耐心等待审核结果，请留意站内短信或者微信提醒！');
                                utilities.refreshUserInfo(function (data) {
                                    //location.reload();
                                });
                            }
                        });
                    }
                });

				/*_(Config.SERVICE.USERCENTER.IS_FULL_INFO, {
					id: sessionStorage.id
				}, function (data) {
					if (data.type === 'ERROR') {
						var r = confirm(data.errmsg);
						if(r)
							location.href = 'uc_profile.html';
					} else {
						_(Config.SERVICE.USERCENTER.MEMBER_UPGRADE, {
							id: sessionStorage.id
						}, function (data) {
							if(data.type === 'SUCCESS'){
								alert('您的升级申请已提交，请耐心等待审核结果，请留意站内短信或者微信提醒！');
								utilities.refreshUserInfo(function (data) {
									location.reload();
								});
							}
						});
					}
				});*/
			}
		}
	});
	app.init();
});
